package com.xiaojiu.mvp.presenter;

import com.xiaojiu.base.BasePresenter;
import com.xiaojiu.bean.PuBuLiuModel;
import com.xiaojiu.mvp.constant.MvpTag;
import com.xiaojiu.mvp.contract.LoginContract;
import com.xiaojiu.rx.RxManager;
import com.xiaojiu.rx.RxSubscriber;

/**
* Created by Jacky on 2017/02/04
*/

public class LoginPresenter extends BasePresenter<LoginContract.View> {

    private LoginContract.Model  mModel;

    public LoginPresenter(){

        mModel = new LoginContract.LoginModelImpl();

    }
    /**
     * 登陆
     *
     * @param account 账号
     * @param pass    密码
     * @return
     */
    public void getLogin1(String account, String pass) {
        mSubscription = RxManager.getInstance().doSubscribe(mModel.getLogin(account, pass), new RxSubscriber<PuBuLiuModel>(mContext, true) {
            @Override
            protected void _onNext(PuBuLiuModel result) {

                mView.onLogin(result);
            }

            @Override
            protected void _onError() {
                mView.onError(MvpTag.TAG1);
            }
        });
    }

    /**
     * 注册
     *
     * @param account 账号
     * @param pass    密码
     * @return
     */
    public void getRegister2(String account, String pass) {
        mSubscription = RxManager.getInstance().doSubscribe(mModel.getLogin(account, pass), new RxSubscriber<PuBuLiuModel>(mContext, true) {
            @Override
            protected void _onNext(PuBuLiuModel result) {

                mView.onRegister(result);
            }

            @Override
            protected void _onError() {
                mView.onError(MvpTag.TAG1);
            }
        });
    }

    /**
     * 验证码
     *
     * @param account 账号
     * @param pass    密码
     * @return
     */
    public void getVerification3(String account, String pass) {
        mSubscription = RxManager.getInstance().doSubscribe(mModel.getLogin(account, pass), new RxSubscriber<PuBuLiuModel>(mContext, true) {
            @Override
            protected void _onNext(PuBuLiuModel result) {

                mView.onVerification(result);
            }

            @Override
            protected void _onError() {
                mView.onError(MvpTag.TAG1);
            }
        });
    }
}